package com.ioe.p2p.util;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.nio.charset.StandardCharsets;

import static com.ioe.p2p.util.CommonUtil.log;

/**
 * @author tanbo
 * @create 2023/10/8
 */
public class MgrUtil {
    public static void send(String text, DatagramChannel dc, InetSocketAddress isd){
        try {
            log("发送内容：" + text);
            dc.send(
                    ByteBuffer.wrap(
                            text.getBytes(StandardCharsets.UTF_8)
                    ),
                    isd
            );
        } catch (IOException e) {
            throw new RuntimeException("数据包" + text + "发送失败", e);
        }
    }
}
